﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections.Specialized;

namespace SF.Base.Core {
	public class BuildEntity {

		/// <summary>
		/// 创建评论实体对象
		/// </summary>
		/// <returns></returns>
		public static DictEntity BuildDictEntity(IDataReader dataReader) {

			DictEntity item = new DictEntity();
			item.Did = Sh.GetLong(dataReader, "did");
			item.DictId = Sh.GetStr(dataReader, "dict_id");
			item.Initial = Sh.GetStr(dataReader, "initial");
			item.ASpell = Sh.GetStr(dataReader, "aspell");
			item.APronunciation = Sh.GetStr(dataReader, "apronunciation");
			item.ASyllable = Sh.GetStr(dataReader, "asyllable");
			item.ESpell = Sh.GetStr(dataReader, "espell");
			item.EPronunciation = Sh.GetStr(dataReader, "epronunciation");
			item.ESyllable = Sh.GetStr(dataReader, "esyllable");
			item.Frequency = Sh.GetInt(dataReader, "frequency");
			item.Paraphrase = Sh.GetStr(dataReader, "paraphrase");
			item.Commentate = Sh.GetStr(dataReader, "commentate");
			item.Status = Sh.GetInt(dataReader, "status");
			return item;
		
		}

		/// <summary>
		/// 创建评论实体对象
		/// </summary>
		/// <returns></returns>
		public static CommentEntity BuildCommentEntity(IDataReader dataReader) {
			CommentEntity item = new CommentEntity();

			//评论相关
			item.CID = Sh.GetLong(dataReader, "cid");
			item.CommentId = Sh.GetStr(dataReader, "comment_id");
			item.CommentDate = Sh.GetDate(dataReader, "comment_date");
			item.Content = Sh.GetStr(dataReader, "content");
			item.CommentType = Sh.GetStr(dataReader, "comment_type");
			item.Approved = Sh.GetInt(dataReader, "approved");
			item.Status = Sh.GetInt(dataReader, "status");

			//用户相关
			item.UserId = Sh.GetStr(dataReader, "user_id");
			item.UID = Sh.GetLong(dataReader, "uid");
			item.Author = Sh.GetStr(dataReader, "author");
			item.Email = Sh.GetStr(dataReader, "email");
			item.Avatar = Sh.GetStr(dataReader, "avatar");
			item.IP = Sh.GetStr(dataReader, "ip");
			item.Agent = Sh.GetStr(dataReader, "agent");

			//祖先
			item.ObjectId = Sh.GetStr(dataReader, "object_id");
			item.ObjectType = Sh.GetStr(dataReader, "object_type");

			//父节点
			item.ParentId = Sh.GetStr(dataReader, "parent");
			item.PID = Sh.GetLong(dataReader, "pid");
			return item;
		}

		/// <summary>
		/// 创建用户实体对象
		/// </summary>
		/// <param name="dataReader"></param>
		/// <returns></returns>
		public static UserEntity BuildUserEntity(IDataReader dataReader) {
			UserEntity user = new UserEntity();

			user.UserId = Sh.GetStr(dataReader, "user_id");
			user.UID = Sh.GetLong(dataReader, "uid");
			user.Login = Sh.GetStr(dataReader, "login");
			user.Pass = Sh.GetStr(dataReader, "pass");
			user.NiceName = Sh.GetStr(dataReader, "nicename");

			user.Email = Sh.GetStr(dataReader, "email");
			user.Url = Sh.GetStr(dataReader, "url");
			user.Registered = Sh.GetDate(dataReader, "registered");
			user.ActivationKey = Sh.GetStr(dataReader, "activationkey");

			user.Status = Sh.GetInt(dataReader, "status");
			user.RealName = Sh.GetStr(dataReader, "realname");
			user.UserMeta = new StringDictionary();

			return user;
		}
	}
}
